package hy.controller;

import hy.entity.Order;
import hy.entity.User;
import hy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderCtrl {
    @Autowired
    OrderService os;
    //localhost/add?customerId=009
    @RequestMapping("add")
    public Order addOrder(Order o){
        os.addOrder(o);
        return o;
    }
    //从ds2数据源查询，因为不符合分表策略
    //localhost/users
    @RequestMapping("users")
    public List<User>getAll(){
        return os.getAll();
    }

    //从两个数据源的两张表中查询，一共查询4张表
    //localhost/orders
    @RequestMapping("orders")
    public List<Order>getOrders(){
        return os.getOrders();
    }
    //根据id值从两个数据源在读取数据
    //localhost/orderId?id=597105702246285312
    @RequestMapping("orderId")
    public Order getOrder(Long id){
        return os.getOrder(id);
    }
}
